#include <iostream>
#include <string.h>
#include <sstream>
#include <dirent.h>
#include <fstream>
using namespace std;
char* rm_smb(char* str)
{
  if(strchr(str,'-')!=NULL&&strlen(strrchr(str,'-'))==1)
  {
   cout<<str[strlen(str)-1]<<endl; 
   str[strlen(str)-1] =char(0);
   cout<<"last"<<endl;
  }
 return str;
}
void clear()

{

        char* dirn; //entry for ./texts
        DIR *dir = NULL;
        struct dirent *drnt = NULL;
        dirn="./texts";
        dir=opendir(dirn);
    
    if(dir)
    {
     int num_doc=0;
                while((drnt = readdir(dir))&&(num_doc<3))
                {
		             if(strstr(drnt->d_name,"20")!=0) 
                 {
                  num_doc++; 
                   //cout<<"---------------\n-----------------\n";
                   cout<<drnt->d_name<<endl;      
                   //cout<<"-----------------\n---------------\n";
                   ifstream infile(drnt->d_name);  //input from file
                   
                   string cln="cln";
                   string proctxt = "./processedtexts/";
                   cln=proctxt+drnt->d_name+cln;
                   ofstream ofile(cln.c_str());
                   char buf[128];
                    //cout<<"w1";
                     while(infile>>buf)
                     {
                     cout<<"before COUT";
                     //cout<<buf<<endl;
                     //cout<<"bef PCH";
                     char* pch;
                     pch = new char[sizeof(buf)];
                     //cout<<"before strtok";
                     pch = strtok (buf," ,.:;%()");
                     while (pch != NULL)
                     {//cout<<"IN WHILE"<<endl;
                      //if(pch[0]!='/')
                      cout<<pch<<endl;
                      ofile<<pch<<endl;
                     // { 
                      //char * pch2 = new char[strlen(pch)+1] ;
                     // strcpy(pch2, pch);
                      //cout<<pch2<<endl;
                     // cout<<rm_smb(pch2);
                      //cout<<endl;
                      pch = strtok (NULL, " ,.:;()%");               
                     // delete[] pch2;
                     // }
                      }
                                                                                   
                     }            
                  infile.close(); 
                  ofile.close();
                   }
                 }
                closedir(dir);
    }
        else
        {
        printf("Can not open directory '%s'\n", dirn);
        }

}


int main(int argc, char** argv )
{
clear();
//char buf[32];
//strcpy(buf,"asdc-");
//cout<<rm_smb(buf);
    
}

